/******************************************************************************
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
*
* Remarks:
*
*   Module to convert a single pulse to level toggle
*
* References:
*
******************************************************************************/

`default_nettype none


/*
//---------------------------------------------------------------------------
// Module: pulse_to_toggle
//
// Remarks:
//    module to convert a single pulse to level toggle
//---------------------------------------------------------------------------
*/

module pulse_to_toggle (
//========== INPUT ==========

	input wire clk,						// clock input
	input wire reset_n,					// reset, active low
	input wire data_in,					// data input, expected to be a single pulse

//========== OUTPUT ==========
	output reg toggle_out				// level toggle out
	
//========== IN/OUT ==========

);

  // parameter for input polarity. By default, it is a positive pulse
  parameter POLARITY = 1;
  
  // pulse to level toggle  
  always @(posedge clk or negedge reset_n) begin
      if (!reset_n) begin
          toggle_out <= 0;    
      end else begin
          if (data_in == POLARITY) begin
            toggle_out <= ~toggle_out;
          end
      end    
  end 
endmodule // pulse_to_toggle

`default_nettype wire
